home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60src.lha / Vim / vim60 / src / gui.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-16  |  16.0 KB  |  496 lines

  1. /* vi:set ts=8 sts=4 sw=4:
  2.  *
  3.  * VIM - Vi IMproved        by Bram Moolenaar
  4.  *                Motif support by Robert Webb
  5.  *
  6.  * Do ":help uganda"  in Vim to read copying and usage conditions.
  7.  * Do ":help credits" in Vim to see a list of people who contributed.
  8.  */
  9.  
  10. /* For debugging */
  11. /* #define D(x)    printf x; */
  12. #define D(x)
  13.  
  14. #if defined(FEAT_GUI_AMIGA)
  15. # include <intuition/intuition.h>
  16. #endif
  17.  
  18. #ifdef FEAT_GUI_MOTIF
  19. # define FEAT_GUI_X11
  20. # include <Xm/Xm.h>
  21. #endif
  22.  
  23. #ifdef FEAT_GUI_ATHENA
  24. # define FEAT_GUI_X11
  25. # include <X11/Intrinsic.h>
  26. # include <X11/StringDefs.h>
  27. #endif
  28.  
  29. #ifdef FEAT_BEVAL
  30. # include "gui_beval.h"
  31. #endif
  32.  
  33. #ifdef FEAT_GUI_GTK
  34. # include <X11/Intrinsic.h>
  35. # include <gtk/gtk.h>
  36. #endif
  37.  
  38. #ifdef FEAT_GUI_BEOS
  39. # include "gui_beos.h"
  40. #endif
  41.  
  42. #ifdef FEAT_GUI_MAC
  43. # include <Types.h>
  44. /*# include <Memory.h>*/
  45. # include <Quickdraw.h>
  46. # include <Fonts.h>
  47. # include <Events.h>
  48. # include <Menus.h>
  49. # if !(defined (TARGET_API_MAC_CARBON) && (TARGET_API_MAC_CARBON))
  50. #   include <Windows.h>
  51. # endif
  52. # include <Controls.h>
  53. /*# include <TextEdit.h>*/
  54. # include <Dialogs.h>
  55. # include <OSUtils.h>
  56. /*
  57. # include <ToolUtils.h>
  58. # include <SegLoad.h>*/
  59. #endif
  60.  
  61. #ifdef RISCOS
  62. # include "gui_riscos.h"
  63. #endif
  64.  
  65. #ifdef FEAT_GUI_PHOTON
  66. # include <Ph.h>
  67. # include <Pt.h>
  68. # include "photon/PxProto.h"
  69. #endif
  70.  
  71. /*
  72.  * On some systems, when we compile with the GUI, we always use it.  On Mac
  73.  * there is no terminal version, and on Windows we can't figure out how to
  74.  * fork one off with :gui.
  75.  */
  76. #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MAC)
  77. # define ALWAYS_USE_GUI
  78. #endif
  79.  
  80. #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MAC)
  81. # define USE_ON_FLY_SCROLL
  82. #endif
  83.  
  84. /*
  85.  * GUIs that support dropping files on a running Vim.
  86.  */
  87. #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MAC) \
  88.     || defined(FEAT_GUI_BEOS) || defined(FEAT_GUI_GTK)
  89. # define HAVE_DROP_FILE
  90. #endif
  91.  
  92. /*
  93.  * This define makes menus always use a fontset.
  94.  * We're not sure if this code always works, thus it can be disabled.
  95.  */
  96. #ifdef FEAT_XFONTSET
  97. # define FONTSET_ALWAYS
  98. #endif
  99.  
  100. /*
  101.  * These macros convert between character row/column and pixel coordinates.
  102.  * TEXT_X   - Convert character column into X pixel coord for drawing strings.
  103.  * TEXT_Y   - Convert character row into Y pixel coord for drawing strings.
  104.  * FILL_X   - Convert character column into X pixel coord for filling the area
  105.  *        under the character.
  106.  * FILL_Y   - Convert character row into Y pixel coord for filling the area
  107.  *        under the character.
  108.  * X_2_COL  - Convert X pixel coord into character column.
  109.  * Y_2_ROW  - Convert Y pixel coord into character row.
  110.  */
  111. #ifdef FEAT_GUI_W32
  112. # define TEXT_X(col)    ((col) * gui.char_width)
  113. # define TEXT_Y(row)    ((row) * gui.char_height + gui.char_ascent)
  114. # define FILL_X(col)    ((col) * gui.char_width)
  115. # define FILL_Y(row)    ((row) * gui.char_height)
  116. # define X_2_COL(x)    ((x) / gui.char_width)
  117. # define Y_2_ROW(y)    ((y) / gui.char_height)
  118. #else
  119. # define TEXT_X(col)    ((col) * gui.char_width  + gui.border_offset)
  120. # define FILL_X(col)    ((col) * gui.char_width  + gui.border_offset)
  121. # define X_2_COL(x)    (((x) - gui.border_offset) / gui.char_width)
  122. # define TEXT_Y(row)    ((row) * gui.char_height + gui.char_ascent \
  123.                             + gui.border_offset)
  124. # define FILL_Y(row)    ((row) * gui.char_height + gui.border_offset)
  125. # define Y_2_ROW(y)    (((y) - gui.border_offset) / gui.char_height)
  126. #endif
  127.  
  128. /* Indices for arrays of scrollbars */
  129. #define SBAR_NONE        -1
  130. #define SBAR_LEFT        0
  131. #define SBAR_RIGHT        1
  132. #define SBAR_BOTTOM        2
  133.  
  134. /* Orientations for scrollbars */
  135. #define SBAR_VERT        0
  136. #define SBAR_HORIZ        1
  137.  
  138. /* Default size of scrollbar */
  139. #define SB_DEFAULT_WIDTH    16
  140.  
  141. /* Default height of the menu bar */
  142. #define MENU_DEFAULT_HEIGHT 1        /* figure it out at runtime */
  143.  
  144. /* Flags for gui_mch_outstr_nowrap() */
  145. #define GUI_MON_WRAP_CURSOR    0x01    /* wrap cursor at end of line */
  146. #define GUI_MON_INVERT        0x02    /* invert the characters */
  147. #define GUI_MON_IS_CURSOR    0x04    /* drawing cursor */
  148. #define GUI_MON_TRS_CURSOR    0x08    /* drawing transparent cursor */
  149. #define GUI_MON_NOCLEAR        0x10    /* don't clear selection */
  150.  
  151. /* Flags for gui_mch_draw_string() */
  152. #define DRAW_TRANSP        0x01    /* draw with transparant bg */
  153. #define DRAW_BOLD        0x02    /* draw bold text */
  154. #define DRAW_UNDERL        0x04    /* draw underline text */
  155. #ifdef RISCOS
  156. # define DRAW_ITALIC        0x08    /* draw italic text */
  157. #endif
  158. #define DRAW_CURSOR        0x10    /* drawing block cursor (win32) */
  159.  
  160. /* For our own tearoff menu item */
  161. #define TEAR_STRING        "-->Detach"
  162. #define TEAR_LEN        (9)    /* length of above string */
  163.  
  164. /* for the toolbar */
  165. #ifdef FEAT_GUI_W16
  166. # define TOOLBAR_BUTTON_HEIGHT    15
  167. # define TOOLBAR_BUTTON_WIDTH    16
  168. #else
  169. # define TOOLBAR_BUTTON_HEIGHT    18
  170. # define TOOLBAR_BUTTON_WIDTH    18
  171. #endif
  172. #define TOOLBAR_BORDER_HEIGHT    12  /* room above+below buttons for MSWindows */
  173.  
  174. #if defined(NO_CONSOLE) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
  175. # define NO_CONSOLE_INPUT    /* use no_console_input() to check if there
  176.                    is no console input possible */
  177. #endif
  178.  
  179. typedef struct GuiScrollbar
  180. {
  181.     long    ident;        /* Unique identifier for each scrollbar */
  182.     struct window *wp;        /* Scrollbar's window, NULL for bottom */
  183.     int        type;        /* one of SBAR_{LEFT,RIGHT,BOTTOM} */
  184.     long    value;        /* Represents top line number visible */
  185.     int        pixval;        /* pixel count of value */
  186.     long    size;        /* Size of scrollbar thumb */
  187.     long    max;        /* Number of lines in buffer */
  188.  
  189.     /* Values measured in characters: */
  190.     int        top;        /* Top of scroll bar (chars from row 0) */
  191.     int        height;        /* Current height of scroll bar in rows */
  192. #ifdef FEAT_VERTSPLIT
  193.     int        width;        /* Current width of scroll bar in cols */
  194. #endif
  195.     int        status_height;    /* Height of status line */
  196. #ifdef FEAT_GUI_X11
  197.     Widget    id;        /* Id of real scroll bar */
  198. #endif
  199. #ifdef FEAT_GUI_GTK
  200.     GtkWidget *id;        /* Id of real scroll bar */
  201. #endif
  202.  
  203. #ifdef FEAT_GUI_MSWIN
  204.     HWND    id;        /* Id of real scroll bar */
  205.     int        scroll_shift;    /* The scrollbar stuff can handle only up to
  206.                    32767 lines.  When the file is longer,
  207.                    scroll_shift is set to the number of shifts
  208.                    to reduce the count.  */
  209. #endif
  210. #if FEAT_GUI_BEOS
  211.     VimScrollBar *id;        /* Pointer to real scroll bar */
  212. #endif
  213. #ifdef FEAT_GUI_MAC
  214.     ControlHandle id;        /* A handle to the scrollbar */
  215. #endif
  216. #ifdef RISCOS
  217.     int        id;        /* Window handle of scrollbar window */
  218. #endif
  219. #ifdef FEAT_GUI_PHOTON
  220.     PtWidget_t    *id;
  221. #endif
  222. } scrollbar_T;
  223.  
  224. typedef long        guicolor_T;    /* handle for a GUI color; for X11 this should
  225.                    be "Pixel", but that's an unsigned and we
  226.                    need a signed value */
  227.  
  228. #ifdef FEAT_GUI_GTK
  229.   typedef GdkFont    *GuiFont;    /* handle for a GUI font */
  230.   typedef GdkFont    *GuiFontset;    /* handle for a GUI fontset */
  231. # define NOFONT        (GuiFont)NULL
  232. # define NOFONTSET    (GuiFontset)NULL
  233. #else
  234. # ifdef FEAT_GUI_PHOTON
  235.   typedef char        *GuiFont;
  236.   typedef char        *GuiFontset;
  237. #  define NOFONT    (GuiFont)NULL
  238. #  define NOFONTSET    (GuiFontset)NULL
  239. # else
  240. #  ifdef FEAT_GUI_X11
  241.   typedef XFontStruct    *GuiFont;    /* handle for a GUI font */
  242.   typedef XFontSet    GuiFontset;    /* handle for a GUI fontset */
  243. #   define NOFONT    (GuiFont)0
  244. #   define NOFONTSET    (GuiFontset)0
  245. #  else
  246.   typedef long_u    GuiFont;    /* handle for a GUI font */
  247.   typedef long_u    GuiFontset;    /* handle for a GUI fontset */
  248. #   define NOFONT    (GuiFont)0
  249. #   define NOFONTSET    (GuiFontset)0
  250. #  endif
  251. # endif
  252. #endif
  253.  
  254. typedef struct Gui
  255. {
  256.     int        in_focus;        /* Vim has input focus */
  257.     int        in_use;            /* Is the GUI being used? */
  258.     int        starting;        /* GUI will start in a little while */
  259.     int        shell_created;        /* Has the shell been created yet? */
  260.     int        dying;            /* Is vim dying? Then output to terminal */
  261.     int        dofork;            /* Use fork() when GUI is starting */
  262.     int        dragged_sb;        /* Which scrollbar being dragged, if any? */
  263.     win_T    *dragged_wp;        /* Which WIN's sb being dragged, if any? */
  264.     int        pointer_hidden;        /* Is the mouse pointer hidden? */
  265.     int        col;            /* Current cursor column in GUI display */
  266.     int        row;            /* Current cursor row in GUI display */
  267.     int        cursor_col;        /* Physical cursor column in GUI display */
  268.     int        cursor_row;        /* Physical cursor row in GUI display */
  269.     char    cursor_is_valid;    /* There is a cursor at cursor_row/col */
  270.     int        num_cols;        /* Number of columns */
  271.     int        num_rows;        /* Number of rows */
  272.     int        scroll_region_top;  /* Top (first) line of scroll region */
  273.     int        scroll_region_bot;  /* Bottom (last) line of scroll region */
  274.     int        scroll_region_left;  /* Left (first) column of scroll region */
  275.     int        scroll_region_right;  /* Right (last) col. of scroll region */
  276.     int        highlight_mask;        /* Highlight attribute mask */
  277.     int        scrollbar_width;    /* Width of vertical scrollbars */
  278.     int        scrollbar_height;   /* Height of horizontal scrollbar */
  279.     int        left_sbar_x;        /* Calculated x coord for left scrollbar */
  280.     int        right_sbar_x;        /* Calculated x coord for right scrollbar */
  281.  
  282. #ifdef FEAT_MENU
  283. # ifndef FEAT_GUI_GTK
  284.     int        menu_height;        /* Height of the menu bar */
  285.     int        menu_width;        /* Width of the menu bar */
  286. # endif
  287.     char    menu_is_active;        /* TRUE if menu is present */
  288. # ifdef FEAT_GUI_ATHENA
  289.     char    menu_height_fixed;  /* TRUE if menu height fixed */
  290. # endif
  291. #endif
  292.  
  293.     scrollbar_T bottom_sbar;        /* Bottom scrollbar */
  294.     int        which_scrollbars[3];/* Which scrollbar boxes are active? */
  295.     int        prev_wrap;        /* For updating the horizontal scrollbar */
  296.     int        char_width;        /* Width of char in pixels */
  297.     int        char_height;        /* Height of char in pixels + 'linespace' */
  298.     int        char_ascent;        /* Ascent of char in pixels */
  299.     int        border_width;        /* Width of our border around text area */
  300.     int        border_offset;        /* Total pixel offset for all borders */
  301.     GuiFont    norm_font;        /* Normal font */
  302.     GuiFont    bold_font;        /* Bold font */
  303.     GuiFont    ital_font;        /* Italic font */
  304.     GuiFont    boldital_font;        /* Bold-Italic font */
  305. #ifdef FEAT_MENU
  306. # ifdef FONTSET_ALWAYS
  307.     GuiFontset    menu_fontset;        /* set of fonts for multi-byte chars */
  308. # else
  309.     GuiFont    menu_font;        /* menu item font */
  310. # endif
  311. #endif
  312. #ifdef FEAT_MBYTE
  313.     GuiFont    wide_font;        /* 'guifontwide' font */
  314. #endif
  315. #ifdef FEAT_XFONTSET
  316.     GuiFontset    fontset;        /* set of fonts for multi-byte chars */
  317. #endif
  318.     guicolor_T    back_pixel;        /* Color of background */
  319.     guicolor_T    norm_pixel;        /* Color of normal text */
  320.     guicolor_T    def_back_pixel;        /* default Color of background */
  321.     guicolor_T    def_norm_pixel;        /* default Color of normal text */
  322.  
  323. #ifdef FEAT_GUI_X11
  324.     char    *rsrc_menu_fg_name;    /* Color of menu and dialog foregound */
  325.     guicolor_T    menu_fg_pixel;        /* Same in Pixel format */
  326.     char    *rsrc_menu_bg_name;    /* Color of menu and dialog backgound */
  327.     guicolor_T    menu_bg_pixel;        /* Same in Pixel format */
  328.     char    *rsrc_scroll_fg_name;    /* Color of scrollbar foreground */
  329.     guicolor_T    scroll_fg_pixel;    /* Same in Pixel format */
  330.     char    *rsrc_scroll_bg_name;    /* Color of scrollbar background */
  331.     guicolor_T    scroll_bg_pixel;    /* Same in Pixel format */
  332.  
  333. # ifdef FEAT_GUI_MOTIF
  334.     guicolor_T    menu_def_fg_pixel;  /* Default menu foreground */
  335.     guicolor_T    menu_def_bg_pixel;  /* Default menu background */
  336.     guicolor_T    scroll_def_fg_pixel;  /* Default scrollbar foreground */
  337.     guicolor_T    scroll_def_bg_pixel;  /* Default scrollbar background */
  338. # endif
  339.     Display    *dpy;            /* X display */
  340.     Window    wid;            /* Window id of text area */
  341.     int        visibility;        /* Is shell partially/fully obscured? */
  342.     GC        text_gc;
  343.     GC        back_gc;
  344.     GC        invert_gc;
  345.     Cursor    blank_pointer;        /* Blank pointer */
  346.  
  347.     /* X Resources */
  348.     char_u    *rsrc_font_name;    /* Resource font name, used if 'guifont'
  349.                        not set */
  350.     char_u    *rsrc_bold_font_name; /* Resource bold font name */
  351.     char_u    *rsrc_ital_font_name; /* Resource italic font name */
  352.     char_u    *rsrc_boldital_font_name;  /* Resource bold-italic font name */
  353.     char_u    *rsrc_menu_font_name;    /* Resource menu Font name */
  354.     Bool    rsrc_rev_video;        /* Use reverse video? */
  355.  
  356.     char_u    *geom;            /* Geometry, eg "80x24" */
  357.     Bool    color_approx;        /* Some color was approximated */
  358. #endif
  359.  
  360. #ifdef FEAT_GUI_GTK
  361.     Display    *dpy;            /* X display */
  362.     int        visibility;        /* Is shell partially/fully obscured? */
  363.     GdkCursor    *blank_pointer;        /* Blank pointer */
  364.  
  365.     /* X Resources */
  366.     char_u    *geom;            /* Geometry, eg "80x24" */
  367.  
  368.     GtkWidget    *mainwin;        /* top level GTK window */
  369.     GtkWidget    *formwin;        /* manages all the windows below */
  370.     GtkWidget    *drawarea;        /* the "text" area */
  371. # ifdef FEAT_MENU
  372.     GtkWidget    *menubar;        /* menubar */
  373. # endif
  374. # ifdef FEAT_TOOLBAR
  375.     GtkWidget    *toolbar;        /* toolbar */
  376. # endif
  377. # ifdef FEAT_GUI_GNOME
  378.     GtkWidget    *menubar_h;        /* menubar handle */
  379.     GtkWidget    *toolbar_h;        /* toolbar handle */
  380. # endif
  381.     GdkColor    *fgcolor;        /* GDK-styled foreground color */
  382.     GdkColor    *bgcolor;        /* GDK-styled background color */
  383.  
  384.     GdkFont    *current_font;
  385.     GdkGC    *text_gc;        /* cached GC for normal text */
  386.  
  387.     GtkAccelGroup *accel_group;
  388.     GtkWidget    *fontdlg;        /* font selection dialog window */
  389.     char_u    *fontname;        /* font name from font selection dialog */
  390.  
  391.     GtkWidget    *filedlg;        /* file selection dialog */
  392.     char_u    *browse_fname;        /* file name from filedlg */
  393. #endif    /* FEAT_GUI_GTK */
  394.  
  395. #ifdef FEAT_FOOTER
  396.     int        footer_height;        /* height of the message footer */
  397. #endif
  398.  
  399. #if defined(FEAT_TOOLBAR) \
  400.     && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF))
  401.     int        toolbar_height;        /* height of the toolbar */
  402. #endif
  403.  
  404. #ifdef FEAT_BEVAL
  405.     /* Tooltip properties; also used for balloon evaluation */
  406.     char_u    *rsrc_tooltip_font_name; /* tooltip font name */
  407.     char    *rsrc_tooltip_fg_name;    /* tooltip foreground color name */
  408.     char    *rsrc_tooltip_bg_name;    /* tooltip background color name */
  409.     guicolor_T    tooltip_fg_pixel;    /* tooltip foreground color */
  410.     guicolor_T    tooltip_bg_pixel;    /* tooltip background color */
  411.     XFontSet    tooltip_fontset;    /* tooltip fontset */
  412. #endif
  413.  
  414. #ifdef FEAT_GUI_MSWIN
  415.     GuiFont    currFont;        /* Current font */
  416.     guicolor_T    currFgColor;        /* Current foreground text color */
  417.     guicolor_T    currBgColor;        /* Current background text color */
  418. #endif
  419.  
  420. #ifdef FEAT_GUI_BEOS
  421.     VimApp     *vimApp;
  422.     VimWindow  *vimWindow;
  423.     VimFormView *vimForm;
  424.     VimTextAreaView *vimTextArea;
  425.     int        vdcmp;            /* Vim Direct Communication Message Port */
  426. #endif
  427.  
  428. #ifdef FEAT_GUI_MAC
  429.     WindowPtr    VimWindow;
  430.     MenuHandle    MacOSHelpMenu;        /* Help menu provided by the MacOS */
  431.     int        MacOSHelpItems;        /* Nr of help-items supplied by MacOS */
  432.     int        MacOSHaveCntxMenu;  /* Contextual menu available */
  433.     WindowPtr    wid;            /* Window id of text area */
  434.     int        visibility;        /* Is window partially/fully obscured? */
  435. #endif
  436.  
  437. #if defined(FEAT_GUI_AMIGA)
  438.     struct Window *window;        /* a handle to the amiga window */
  439.     struct Menu      *menu;        /* a pointer to the first menu */
  440.     struct TextFont *textfont;        /* a pointer to the font structure */
  441. #endif
  442.  
  443. #ifdef RISCOS
  444.     int        window_handle;
  445.     char_u    *window_title;
  446.     int        window_title_size;
  447.     int        fg_colour;        /* in 0xBBGGRR format */
  448.     int        bg_colour;
  449. #endif
  450.  
  451. #ifdef FEAT_GUI_PHOTON
  452.     PtWidget_t    *vimWindow;        /* PtWindow */
  453.     PtWidget_t    *vimTextArea;        /* PtRaw */
  454.     PtWidget_t    *vimContainer;        /* PtPanel */
  455. # if defined(FEAT_MENU) || defined(FEAT_TOOLBAR)
  456.     PtWidget_t    *vimToolBarGroup;
  457. # endif
  458. # ifdef FEAT_MENU
  459.     PtWidget_t    *vimMenuBar;
  460. # endif
  461. # ifdef FEAT_TOOLBAR
  462.     PtWidget_t    *vimToolBar;
  463.     int        toolbar_height;
  464. # endif
  465.     PhEvent_t    *event_buffer;
  466. #endif
  467.  
  468. #ifdef FEAT_XIM
  469.     char    *rsrc_input_method;
  470.     char    *rsrc_preedit_type_name;
  471. #endif
  472. } gui_T;
  473.  
  474. extern gui_T gui;            /* this is defined in gui.c */
  475.  
  476. /* definitions of available window positionings for gui_*_position_in_parent()
  477.  */
  478. typedef enum
  479. {
  480.     VW_POS_MOUSE,
  481.     VW_POS_CENTER,
  482.     VW_POS_TOP_CENTER
  483. } gui_win_pos_T;
  484.  
  485. #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK)
  486. /*
  487.  * Flags used to distinguish the different contexts in which the
  488.  * find/replace callback may be called.
  489.  */
  490. # define FR_FINDNEXT    1    /* Find next in find dialog */
  491. # define FR_R_FINDNEXT    2    /* Find next in repl dialog */
  492. # define FR_REPLACE    3
  493. # define FR_REPLACEALL    4
  494. # define FR_UNDO    5
  495. #endif
  496.